﻿#ifndef MAINSERVICE_H
#define MAINSERVICE_H

#include <QObject>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QDebug>
#include <QFontDatabase>
#include <QFont>

#include "model/qmlserialport.h"
#include "model/qmlrelayswitch.h"
#include "model/qmlporxyconfig.h"
#include "model/qmllogsbrowser.h"
#include "http/httpserver.h"

class MainService : public QObject
{
    Q_OBJECT
public:
    explicit MainService(QObject *parent = nullptr);
    explicit MainService(QGuiApplication *app, QQmlApplicationEngine *engine, QObject *parent = nullptr);
    static MainService *getInstance();
    static MainService *getInstance(QGuiApplication *app, QQmlApplicationEngine *engine);

signals:
    void logsPrintSignal(QString s);

private slots:
    // PorxyConfig
    void qmlPorxyConfig_startSlot(int port);
    void qmlPorxyConfig_stopSlot();

public:
    void start();

private:
    QmlSerialPort     *mQmlSerialPortService;
    QmlRelaySwitch    *mQmlRelaySwitchService;
    QmlPorxyConfig    *mQmlPorxyConfigService;
    QmlLogsBrowser    *mQmlLogsBrowserService;
    // Http Server
    HttpServer        *mHttpServerService;
    // engine
    QQmlApplicationEngine *mQQmlApplicationEngineService;
    QGuiApplication   *mQGuiApplicationService;

    void log(QString s);

};

#endif // MAINSERVICE_H
